package com.example.sort.sort;

import mckaylib.ga.engine.core.builders.FitnessBuilder;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuple3;
import reactor.util.function.Tuples;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo1FitnessBuilder implements FitnessBuilder {
    @Override
    public Tuple2<Map<String, Object>, List<Tuple3<String, String, Double>>> build() {

        Map<String, Object> objConfigs= buildObjectAndConfigs();
        List<Tuple3<String, String, Double>> fitnessConfigs=buildFitnessConfigs();

        return Tuples.of(objConfigs, fitnessConfigs);
    }


    private Map<String, Object> buildObjectAndConfigs() {

        Map<String, Object> configs=new HashMap<>();

        //这里定义的是n个适应度函数所在的对象（此处只定义了1个，也可以多个）
        Demo1SolutionConverter obj=new Demo1SolutionConverter();
        configs.put("obj", obj);

        return configs;
    }

    private List<Tuple3<String, String, Double>> buildFitnessConfigs() {
        List<Tuple3<String, String, Double>> fitnessConfigs = new ArrayList<>();
        //obj和上面的对应，getRate指明了适应度函数是在obj这个对象中方法名为getRate的函数
        //此处也可以多个
        //1D代表默认权重，也可以定期较低的权重，比如：0.5D这种　
        fitnessConfigs.add(Tuples.of("obj", "getRate", 1D));

        return fitnessConfigs;
    }
}
